//
//  BaseViewController.swift
//  SinaBlog
//
//  Created by 李超 on 16/3/20.
//  Copyright © 2016年 lichao. All rights reserved.
//

import UIKit

//利用扩展来进行实现代理
extension BaseViewController:VisitorViewDelegate{
    
    //用户注册
    func visitorViewRegister() {
        
      print("BaseViewController:\(__FUNCTION__)")
        
    }
    //用户登录
    func visitorViewLogin() {
        
        print("BaseViewController:\(__FUNCTION__)")
        //执行登陆操作
        let loginVC = LoginViewController()
        //Model出控制器
        presentViewController(UINavigationController(rootViewController: loginVC), animated: true, completion: nil)
    }
    
    
}

class BaseViewController: UITableViewController {

    override func viewDidLoad() {
        
        super.viewDidLoad()
                
    }
        
    //重写加载视图方法
    override func loadView() {
        //登陆状态为真则加载父视图，假则加载登陆画面的视图
        CZUserAccountTool.shareInstance.userLogin ? super.loadView() : setupVisitorView()
        
    }
 
    //如果不登录执行自定义的view视图
    private func setupVisitorView(){
        
        view = visitor
        //view.backgroundColor = UIColor.brownColor()
        
        //添加导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style:UIBarButtonItemStyle.Plain , target: nil, action: nil)
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style:UIBarButtonItemStyle.Plain , target: nil, action: nil)
        
        
        //根据控制器的类型进行设置显示页面的信息
        if self is HomeViewController{
            visitor.startAnimationRatation()
            
        }else if self is MessageViewController {
           
          visitor.setVisitorViewInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
        }else if self is DiscoverViewController{
            
           visitor.setVisitorViewInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is ProfileViewController{
          visitor.setVisitorViewInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")  
            
        }
        
        //成为visitorView的代理处理点击事件
        visitor.delegate = self
    }
   

    
    //懒加载访问视图
    private lazy var visitor:VisitorView = {
        
        let view = VisitorView()
        return view
        
    }()
   
    
}
